/**
 * 
 */
package com.fwzc.giuseppe.adapter;

import java.util.ArrayList;
import java.util.HashMap;

import com.fwzc.giuseppe.MyApplication;
import com.fwzc.giuseppe.R;
import com.fwzc.giuseppe.config.Config;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * 类名称：MsgAdapter 类描述： 创建人：何琳 创建时间：2015年8月13日 下午3:11:14
 * 
 * @version
 * 
 */
public class AccountsAdapter extends BaseAdapter {

	private ArrayList<HashMap<String, String>> dataList;
	private Context context;
	private ImageLoader imageLoader;
	
	public AccountsAdapter(Context context,
			ArrayList<HashMap<String, String>> dataList) {
		this.context = context;
		this.dataList = dataList;

		imageLoader = ImageLoader.getInstance();
		imageLoader.init(ImageLoaderConfiguration.createDefault(context));
	}

	@Override
	public int getCount() {
		return dataList.size();
	}

	@Override
	public Object getItem(int position) {
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.layout_switch_account_item, null);
			holder.img = (ImageView) convertView.findViewById(R.id.account_userimg);
			holder.name = (TextView) convertView.findViewById(R.id.account_username);
			convertView.setTag(holder);
		}else {
			holder = (ViewHolder) convertView.getTag();
		}
		HashMap<String, String> map = dataList.get(position);
		imageLoader.displayImage(map.get("imageUrl"), holder.img, Config.no_iv_option);//图片+
		holder.name.setText(map.get("name"));
		return convertView;
	}

	private class ViewHolder {
		ImageView img;
		TextView name;
	}
}
